import request from '@/utils/request'
import { fileupload, downloadFile } from "../api/contract";
export function login(data) {
  return request({
    url: '/authentication',
    method: 'post',
    data: data
  })
};

export function list(data) {
  return request({
    url: '/PurchaseRequisition/list',
    method: 'get',
    params: data
  })
};

// 提交 修改
export function submit(data) {
  return request({
    url: '/PurchaseRequisition/update',
    method: 'post',
    data: data
  })
}

// 新增
export function add(data) {
  return request({
    url: '/PurchaseRequisition/add',
    method: 'post',
    data: data
  })
}


// 删除
export function del(id) {
  return request({
    url: '/PurchaseRequisition/delete',
    method: 'put',
    params: {
      id: id
    }
  })
}
export function PRlist(data) {
  return request({
    url: '/PurchaseRequirements/PRlist',
    method: 'get',
    params: data
  })
}

// 上传文件
export function upload(dataFile) {
  // 原生 const dataFile = event.target.files[0];
  // 组件 const dataFile = event.raw;
  console.log("文件" + dataFile)
  if (!dataFile) {
    alert("请选择一个文件");
    return;
  }
  const formData = new FormData();
  formData.append('uploadfile', dataFile);
  console.log(formData.get('uploadfile'))
  return fileupload(formData).then(res => {
    if (res.code == 200) {
      console.log("成功：", res)
      alert('文件上传成功')
    } else {
      console.log("失败：", res)
      alert('文件上传失败')
    }

  })
}



// 发票模块
export function invoiceAdd(data) {
  return request({
    url: '/PurchaseInvoice/add',
    method: 'post',
    data: data
  })
}
// 发票模块完毕

export function lookinvoice(data) {
  return request({
    url: '/finance/selectInvoice',
    method: 'get',
    params: data
  })
}
